package cn.cms.chuangjia.controller;

import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.cms.chuangjia.domain.Admin;
import cn.cms.chuangjia.domain.Menu;
import cn.cms.chuangjia.vo.AjaxResult;
import cn.cms.chuangjia.vo.Page;
import com.github.pagehelper.PageInfo;
//import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
//import com.ruoyi.common.annotation.Log;
//import com.ruoyi.common.core.controller.BaseController;
//import com.ruoyi.common.core.domain.AjaxResult;
//import com.ruoyi.common.enums.BusinessType;
import cn.cms.chuangjia.service.IMenuService;


/**
 * menuController
 * 
 * @author ruoyi
 * @date 2024-01-18
 */
@RestController
@RequestMapping("/cms/menu")
public class MenuController extends BaseController
{
    @Autowired
    private IMenuService menuService;

    /**
     * 查询menu列表
     */
    //@PreAuthorize("@ss.hasPermi('menu:menu:list')")
    @GetMapping("/list")
    public Page<Menu> list(Menu menu)
    {
        startPage();
        return menuService.selectMenuList(menu);
    }

    /**
     * 导出menu列表
     */
    //@PreAuthorize("@ss.hasPermi('menu:menu:export')")
    //@Log(title = "menu", businessType = BusinessType.EXPORT)
//    @PostMapping("/export")
//    public void export(HttpServletResponse response, Menu menu)
//    {
//        List<Menu> list = menuService.selectMenuList(menu);
//        ExcelUtil<Menu> util = new ExcelUtil<Menu>(Menu.class);
//        util.exportExcel(response, list, "menu数据");
//    }

    /**
     * 获取menu详细信息
     */
    //@PreAuthorize("@ss.hasPermi('menu:menu:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return AjaxResult.success(menuService.selectMenuById(id));
    }

    /**
     * 新增menu
     */
    //@PreAuthorize("@ss.hasPermi('menu:menu:add')")
    //@Log(title = "menu", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Menu menu)
    {
        Admin admin=getUser();
        //Admin admin= (Admin) request.getSession().getAttribute("Admin");
        menu.setPoster(admin.getRealname());//真名
        return AjaxResult.toAjax(menuService.insertMenu(menu));
    }

    /**
     * 修改menu
     */
    //@PreAuthorize("@ss.hasPermi('menu:menu:edit')")
    //@Log(title = "menu", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Menu menu)
    {
        return AjaxResult.toAjax(menuService.updateMenu(menu));
    }

    /**
     * 删除menu
     */
    ///@PreAuthorize("@ss.hasPermi('menu:menu:remove')")
    //@Log(title = "menu", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return AjaxResult.toAjax(menuService.deleteMenuByIds(ids));
    }
    @DeleteMapping("del/{id}")
    public AjaxResult del(@PathVariable Integer id)
    {
        return AjaxResult.toAjax(menuService.deleteMenuById(id));
    }
}
